package logic

import (
	"context"
	"shop/models/mysql"

	"shop/shoprpc/internal/svc"
	"shop/shoprpc/shoprpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShopListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopListLogic {
	return &ShopListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShopListLogic) ShopList(in *shoprpc.ShopListRequest) (*shoprpc.ShopListResponse, error) {
	// todo: add your logic here and delete this line
	var shops []mysql.Shop
	mysql.DB.Debug().Find(&shops)

	var ShopList []*shoprpc.ShopList
	for _, shop := range shops {
		list := shoprpc.ShopList{
			Name:   shop.Name,
			Price:  float32(shop.Price),
			Number: int64(shop.Number),
			Status: int64(shop.Status),
		}
		ShopList = append(ShopList, &list)
	}
	return &shoprpc.ShopListResponse{
		List: ShopList,
	}, nil
}
